package com.drivingtheproject.wifie.wifiexpert;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Parcel;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;

import com.drivingtheproject.wifie.com.drivingtheproject.wifie.common.Constants;
import com.drivingtheproject.wifie.data.Profile;


public class ProfileActivity extends BaseActivity {

    private  TextView textViewSSID;
    private  TextView textViewReceiver;
    private  TextView textViewMessage;
    private EditText  editTextName;
    private EditText  editTextReceiver;
    private EditText  editTextMessage;
    private CheckBox checkBoxBluetoothOn;

    private CheckBox checkBoxActive;
    private Spinner spinnerMode;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.profile_layout);
        final CheckBox checkBoxNotify;

        this.textViewSSID=(TextView) findViewById(R.id.textViewSSID);
        this.textViewReceiver=(TextView) findViewById(R.id.textViewReceiver);
        this.textViewMessage=(TextView) findViewById(R.id.textViewMessage);

        this.editTextName = (EditText) findViewById(R.id.editTextName);
        this.editTextReceiver = (EditText) findViewById(R.id.editTextReceiver);
        this.editTextMessage = (EditText) findViewById(R.id.editTextMessage);
        this.checkBoxBluetoothOn=(CheckBox)findViewById(R.id.checkBoxBluetoothOn);
        checkBoxNotify=(CheckBox)findViewById(R.id.checkBoxNotify);
        checkBoxNotify.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                setNotificationVisibility(checkBoxNotify.isChecked());
            }

        });


        this.checkBoxActive=(CheckBox)findViewById(R.id.checkBoxActive);
        this.spinnerMode=(Spinner)findViewById(R.id.spinnerMode);

        Intent intent = getIntent();
        Profile profile =(Profile)intent.getParcelableExtra(Constants.SELECTED_PROFILE);
        if(profile!=null)
        {
            this.textViewSSID.setText(profile.getSSID());
            this.editTextName.setText(profile.getName());
            editTextReceiver.setText(profile.getContactNumber());
            editTextMessage.setText(profile.getMessage());

            this.checkBoxBluetoothOn.setChecked(profile.isBluetoothOn());
            checkBoxNotify.setChecked(profile.isSendMessage());
            this.checkBoxActive.setChecked(profile.isEnable());
            this.spinnerMode.setSelection(profile.getMode().value());
        }
        this.setNotificationVisibility(checkBoxNotify.isChecked());
    }

    private void setNotificationVisibility(boolean isVisible) {

        if(isVisible)
        {
            editTextReceiver.setVisibility(View.VISIBLE);
            editTextMessage.setVisibility(View.VISIBLE);
            this.textViewMessage.setVisibility(View.VISIBLE);
            this.textViewReceiver.setVisibility(View.VISIBLE);
        }
        else
        {
            editTextReceiver.setVisibility(View.GONE);
            editTextMessage.setVisibility(View.GONE);
            this.textViewMessage.setVisibility(View.GONE);
            this.textViewReceiver.setVisibility(View.GONE);
        }
    }
}
